package dynamicprogramming;

/**
 * @Author: LDeng
 * @Date: 2021-04-25 11:57
 */
//求最大上升子序列长度
public class LIS {
    public static void main(String[] args) {
        System.out.println(lengthOfLIS(new int[]{10, 2, 2, 5, 1, 7, 101, 18}));

    }

    static int lengthOfLIS(int[] nums) {
        if(nums==null||nums.length==0) return 0;
        int[] dp=new int[nums.length];
        dp[0]=1;
        int maxLength=1;
        for (int i = 0; i < dp.length; i++) {
            dp[i]=1;
            for (int j = 0; j < i; j++) {
                if(nums[i]<=nums[j]) continue;
                dp[i]=Math.max(dp[i],dp[j]+1);
            }
            maxLength=Math.max(dp[i],maxLength);
        }
        return maxLength;
    }


}
